var config = require("../../../config.js")

Page({
  data: {
    objHostName:`${config.service.objHostName}`,
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    bigtyp:0,
    decorationList:['毛坯', '简装', '中装', '豪装']
  },
  onLoad: function (param) {
   
    var that = this;
    console.log('id:'+param.id)
    var bigtyp = param.bigtyp
    console.log('bigtyp:'+param.bigtyp)
    this.setData({
      id: param.id,
      bigtyp: param.bigtyp
    });
    var titles = ['转让详情', '商铺详情', '写字楼详情', '土地厂房详情']
    wx.setNavigationBarTitle({
      title: titles[bigtyp],
    })

    
    var url = `${config.service.homeDetail}`
    wx.request({
      url: url,
      method: 'POST',
      data:{
        id:param.id
      },
      success:e=>{

        var code = e.data.code;
        if (code!=null && code == 0) {
          var res = e.data.res;
          var img = res['img'];
          var imgs = img.split(',');
          var newImgs = [];
          for(let i in imgs)
          {
            newImgs.push(that.data.objHostName+imgs[i])
          }
          if(newImgs.length<=1)
          {
            that.setData({
              indicatorDots:false
            });
          }
          console.log(newImgs);
          res.imgs = newImgs;
          that.setData({
            res:res
          });
        }

        console.log(e.data.res);
      },
      fail:fail=>
      {
        console.log(fail)
      }
    })
  },

  makephonecall:function(e)
  {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.res.tel,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },

  leaveMsg:function(e)
  {
    console.log('留言')
  },
  onShareAppMessage:function(e)
  {
    var that = this;
    return {

      title: that.data.res.title,

      desc: '描述',

      path: '/pages/home/index?bigtyp='+that.data.bigtyp+'&id='+that.data.id

    }
  },
  imgYu:function(e){
    var that = this;
    // console.log(e)
    var src = e.target.dataset.src;
    wx.previewImage({
      urls: that.data.res.imgs,
      current:src
    })
  }
  
})